package com.qianfeng.smartdevices.config;


import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;


@Configuration //声明是一个配置类
@EnableAsync(proxyTargetClass = true)//开启异步支持
public class MyConfig {


    //数据库的连接池
//    @Bean
//    public DataSource dataSource() {
//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setUrl("jdbc:mysql:///smartdevice?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimeZone=Asia/Shanghai");
//        dataSource.setUsername("root");
//        dataSource.setPassword("376876hT##");
//        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
//        dataSource.setMaxActive(100);//最大连接数
//        dataSource.setMinIdle(5);//最小空闲数,低于这个数量就开始扩容,直到扩容到最大数量为止
//        dataSource.setMaxWait(5000);//最大等待时间,在时间内获取不到连接就超时
//        dataSource.setInitialSize(10);//初始的长度
//        return dataSource;
//    }
    //sqlsessionfactorybean
//    @Bean
//    public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
//        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
//        factoryBean.setDataSource(dataSource);
//        factoryBean.setConfigLocation(new ClassPathResource("mybatis.xml"));
//        return factoryBean;
//    }

    //mapper 的扫描
//    @Bean
//    public MapperScannerConfigurer mapperScannerConfigurer() {
//        MapperScannerConfigurer configurer = new MapperScannerConfigurer();
//        configurer.setBasePackage("com.qianfeng.smartdevices.mapper");
//        return configurer;
//    }


//    事务的平台管理器
//    @Bean
//    public DataSourceTransactionManager transactionManager(DataSource dataSource) {
//        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(dataSource);
//        return transactionManager;
//    }
    @Bean
    public ObjectMapper objectMapper() {return new ObjectMapper();}
    @Bean
    public BCryptPasswordEncoder passwordEncoder() {return new BCryptPasswordEncoder();}


}
